package com.kingdee.shr.ques.cloud.poi;

import com.kingdee.shr.ques.cloud.bo.IdListVO;
import com.kingdee.shr.ques.cloud.bo.PageRequestParam;
import com.kingdee.shr.ques.cloud.poi.function.ExportFunction;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author Miaoxiong Fan
 * @description 分页、选中导出工具类
 * 导出列子
 * TestQuestionService export
 * 导入例子
 * TestQuestionService import
 * @data 2019/1/29
 */
public class  ExportByPager<S extends ServicePager , T> implements ExportFunction<IdListVO , T> {

    private ServicePager service;

    public ExportByPager(ServicePager service) {
        this.service = service;
    }

    @Override
    public List<T> pageQuery(IdListVO idListVO, int page, int pageSize) {
        if(null != idListVO && !StringUtils.isEmpty(idListVO.getIds())) {
            return service.getAll(idListVO);
        }else {
            PageRequestParam pager = new PageRequestParam();
            pager.setPageSize(pageSize);
            pager.setPageNo(page);
            return service.getByPage(null , pager).getRows();
        }
    }

    @Override
    public Object convert(T t) {
        return t;
    }
}
